<!-- 学员考试情况 -->
<template>
  <div class="pxbCourse">
    <div class="search">
      <el-form
        ref="form"
        :model="queryParams.params"
        label-width="0"
        style="display: flex; align-items: center"
      >
        <el-form-item style="margin-bottom: 0">
          <el-input
            v-model="queryParams.params.name"
            placeholder="姓名"
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="button">
        <el-button type="primary" icon="el-icon-search" @click="inquire"
          >查询</el-button
        >
        <!-- <el-button
          type="danger"
          icon="el-icon-back"
          @click="goBack"
          style="margin-left: 10px"
          >返回</el-button
        > -->
      </div>
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        border
        height="calc(100vh - 300px)"
        style="width: 100%"
        :header-cell-style="{
          background: '#f2f3f4',
          color: '#555',
          'font-weight': 'bold',
          'line-height': '32px',
        }"
      >
        <el-table-column prop="name" label="姓名" width="180">
        </el-table-column>
        <el-table-column prop="gender" label="性别" width="120">
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号"> </el-table-column>
        <el-table-column prop="education" label="学历"> </el-table-column>

        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="small"
              icon="el-icon-view"
              @click="InformationFilling(scope.row)"
              >评分</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryParams.current"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="queryParams.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog
      title="评分"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <div>
        <el-form
          :model="queryMap"
          ref="queryMap"
          :disabled="disabled"
          :rules="rules"
          label-width="150px"
        >
          <el-form-item label="出勤情况 (15分)" prop="attendanceScore">
            <el-input
              v-model.number="queryMap.attendanceScore"
              min="0"
              max="15"
              type="number"
            ></el-input>
          </el-form-item>
          <el-form-item label="纪律执行 (15分)" prop="disciplineScore">
            <el-input
              min="0"
              max="15"
              v-model.number="queryMap.disciplineScore"
              type="number"
            ></el-input>
          </el-form-item>
          <el-form-item label="学习表现 (20分)" prop="performanceScore">
            <el-input
              min="0"
              max="20"
              v-model.number="queryMap.performanceScore"
              type="number"
            ></el-input>
          </el-form-item>
          <el-form-item label="实训表现 (20分)" prop="practicalScore">
            <el-input
              min="0"
              max="20"
              v-model.number="queryMap.practicalScore"
              type="number"
            ></el-input>
          </el-form-item>
          <el-form-item label="知识掌握 (30分)" prop="knowledgeScore">
            <el-input
              min="0"
              max="30"
              v-model.number="queryMap.knowledgeScore"
              type="number"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addCourse">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  fetchTraineeList,
  studentExamGet,
  studentExamSave,
} from "@/api/OneStageOneGear/OneStageOneGear.js";
export default {
  data() {
    return {
      tableData: [],
      queryMap: {
        attendanceScore: 0,
        disciplineScore: 0,
        examScore: 0,
        id: "",
        knowledgeScore: 0,
        performanceScore: 0,
        practicalScore: 0,
      },
      total: 0,
      queryParams: {
        current: 1,
        orderBy: "",
        params: {
          birthplace: "",
          createTime: "",
          createdBy: "",
          dob: "",
          education: "",
          ethnicity: "",
          gender: "",
          graduatingSchool: "",
          id: "",
          idCard: "",
          isDeleted: true,
          name: "",
          phone: "",
          politicalStatus: "",
          position: "",
          trainingClassInfoId: this.$route.query.id,
          updateBy: "",
          updateTime: "",
          workplace: "",
        },
        size: 10,
      },
      dialogVisible: false,
      disabled: false,
      rules: {
          attendanceScore: [
            { required: true, message: '请输入出勤情况分数', trigger: 'blur' },
            {type:'number',min:0,max:15, message: '分数区间为0~15', trigger: 'blur'}
          ],
          disciplineScore: [
            { required: true, message: '请输入纪律执行分数', trigger: 'blur' },
            {type:'number',min:0,max:15, message: '分数区间为0~15', trigger: 'blur'}
          ],
          performanceScore: [
            { required: true, message: '请输入学习表现分数', trigger: 'blur' },
            {type:'number',min:0,max:20, message: '分数区间为0~20', trigger: 'blur'}
          ],
          practicalScore: [
            { required: true, message: '请输入实训表现分数', trigger: 'blur' },
            {type:'number',min:0,max:20, message: '分数区间为0~20', trigger: 'blur'}
          ],
          knowledgeScore: [
            { required: true, message: '请输入知识掌握分数', trigger: 'blur' },
            {type:'number',min:0,max:30, message: '分数区间为0~30', trigger: 'blur'}
          ],
        }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    inquire() {
      this.queryParams.current = 1;
      this.getList();
    },
    reset() {
      this.$refs.form.resetFields();
    },
    //详情
    async particulars(id) {
      let res = await studentExamGet(id);
      this.queryMap = res.data;
      this.queryMap.studentId = id;
    },
    //查看、修改、新增
    InformationFilling(row) {
      this.particulars(row.id);
      this.dialogVisible = true;
      this.disabled = false;
    },
    //新增/修改
    async addCourse() {
      this.$refs.queryMap.validate(async (valid) => {
        let res = await studentExamSave(this.queryMap);
        if (valid){
          if (res.code == 200) {
            this.$message({message:"评分成功", type:"success"});
            this.dialogVisible = false;
            this.getList();
          }
        } else {
          return false;
        }
      })
    },
    async getList() {
      let res = await fetchTraineeList(this.queryParams);
      console.log(res);
      if (res.code == 200) {
        this.tableData = res.data.records;
        this.total = res.data.total;
      }
    },
    handleSizeChange(val) {
      this.queryParams.size = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.current = val;
      this.getList();
    },
    handleClose(done) {
      done();
    },
  },
};
</script>
<style lang="less" scoped>
.pxbCourse {
  height: calc(100vh - 100px);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .search {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    .button {
      display: flex;
      justify-content: flex-end;
    }
  }
  .table {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: calc(100% - 50px);
    .pagination {
      margin-top: 20px;
      text-align: right;
    }
  }
}
</style>
